<template>
    <div class="page-store-platform-store-present bg-content">
        <scroll-view scroll-x="true">
            <div class="table table-bordered" style="text-align: center; background: white; width: 1600px; overflow: auto;">
                <div class="tr">
                    <div class="td text-center bold" style="width: 200%;">请输入使用优惠券的最低金额（单位/元）</div>
                    <div class="td text-center bold">优惠券金额（单位/元）</div>
                    <div class="td text-center bold">数量</div>
                    <div class="td text-center bold">已使用数量</div>
                    <div class="td text-center bold" style="width: 200%;">每个用户最多可以领取的数量</div>
                    <div class="td text-center bold">开始时间</div>
                    <div class="td text-center bold">结束时间</div>
                    <div class="td text-center bold">类型</div>
                    <div class="td text-center bold">状态</div>
                    <div class="td text-center bold">显示顺序</div>
                    <div class="td text-center bold">创建时间</div>
                    <div class="td text-center bold">最后更新时间</div>
                    <div class="td text-center bold">备注</div>
                    <div class="td text-center bold">操作</div>
                </div>
                <div class="tr" v-for="(item, index) in tbGoodsCouponList" :key="item.id">
                    <div class="td" style="width: 200%;">{{item.orderMoney | toEmptyStr}}</div>
                    <div class="td">{{item.couponMoney | toEmptyStr}}</div>
                    <div class="td">{{item.quantity | toEmptyStr}}</div>
                    <div class="td">{{item.usedQuantity | toEmptyStr}}</div>
                    <div class="td" style="width: 200%;">{{item.receiveNumber | toEmptyStr}}</div>
                    <div class="td">{{item.startTime | toEmptyStr}}</div>
                    <div class="td">{{item.endTime | toEmptyStr}}</div>
                    <div class="td">{{item.typeText | toEmptyStr}}</div>
                    <div class="td">{{item.statusText | toEmptyStr}}</div>
                    <div class="td">{{item.displayOrder | toEmptyStr}}</div>
                    <div class="td">{{item.createTime | toEmptyStr}}</div>
                    <div class="td">{{item.lastUpdateTime | toEmptyStr}}</div>
                    <div class="td">{{item.remark | toEmptyStr}}</div>

                    <div class="td">
                        <div style="margin-top: 5px; text-decoration: underline;"
                             @click="navigateTo('/pages/sub/sub2-store-platform/store-platform/store-platform-store-manage/store-platform-store-coupon/store-platform-store-coupon-edit/index', null, item)">
                            编辑
                        </div>
                        <div style="margin-top: 10px; margin-bottom: 10px; text-decoration: underline;" @click="deleteItem(item)">
                            删除
                        </div>
                    </div>
                </div>
            </div>
        </scroll-view>

        <div style="padding-top: 50px;" v-if="!tbGoodsCouponList.length">
            <u-empty text="数据为空" mode="data"></u-empty>
        </div>

        <div style="padding-bottom: 60px;"></div>

        <div class="custom-bottom-button">
            <label @click="navigateTo('/pages/sub/sub2-store-platform/store-platform/store-platform-store-manage/store-platform-store-coupon/store-platform-store-coupon-add/index')">
                添加优惠券
            </label>
        </div>
    </div>
</template>

<script>
    import {CommonUtil} from "@/dev/core/utils/common.util";
    import {TbStoreCouponService} from "@/dev/services/tb-store-coupon.service";

    export default {
        data() {
            return {
                tbGoodsCouponList: []
            }
        },
        onShow() {
            this.findTbStoreCouponList();
        },
        methods: {
            findTbStoreCouponList() {
                const _self = this;
                new TbStoreCouponService().findTbStoreCouponList({
                    storeId: _self.globalVariable.userInfo.tbStore.id,
                }).then(result => {
                    _self.tbGoodsCouponList = result;
                });
            },
            /**
             * 删除
             */
            deleteItem(item) {
                const _self = this;
                CommonUtil.alert({
                    title: '提示！',
                    content: '你确定要删除吗？',
                    showCancel: true, // 是否显示取消按钮
                    success: function (res) {
                        if (res.cancel) { // 点击取消,默认隐藏弹框

                        } else { // 点击确定
                            new TbStoreCouponService().deleteTbStoreCouponByIds(item.id).then(result => {
                                CommonUtil.toast('删除成功');
                                _self.findTbStoreCouponList();
                            });
                        }
                    }
                });
            }
        }
    }
</script>
